home *** CD-ROM | disk | FTP | other *** search
/ Aminet 21 / Aminet 21 (1997)(GTI - Schatztruhe)[!][Oct 1997].iso / Aminet / comm / bbs / Cit_Util_7H21.lha / Citadel_nlstat.lha / nlstat.c < prev    next >
C/C++ Source or Header  |  1993-02-14  |  12KB  |  343 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <math.h>
  4. #include <stdlib.h>
  5. #define UP "System brought up"
  6. #define DOWN "System brought down"
  7. #define NET "System in network mode"
  8. #define NOLOGIN "<No Login>"
  9. #define BAUD300 "300)"
  10. #define BAUD1200 "1200)"
  11. #define BAUD2400 "2400)"
  12. #define BAUD4800 "4800)"
  13. #define BAUD9600 "9600)"
  14. #define BAUD19200 "19200)"
  15. #define CONSOLE "sysConsole)"
  16. #define DEFAULT_READ "calllog.sys"
  17. #define DEFAULT_WRITE "dumbstats"
  18. main (int argc, char *argv[])
  19.   {
  20.   long calls, net, timeout, error, badword, chat;
  21.   long nologin, restart, calltime[96], nettime[96], tottime[96];
  22.   long duration[1440], baud[7], i, j, k, l, longest, lasthour, atime;
  23.   long lastmin, h1, h2, m1, m2, newuser = 0, stay = 0, busytime[96];
  24.   char firstdate[10], firsttime[10], buffer[80], *name, *date, *starthour,
  25.   *startmin, *stophour, *stopmin, *other, *readname, *writename;
  26.   char lasttime[10],lastdate[10];
  27.   FILE *readfile, *writefile;
  28.  
  29.   calls = net = timeout = error = badword = chat = nologin = 0;
  30.   restart = longest = atime = newuser = stay = 0;
  31.  
  32.   printf ("Citadel log file cruncher Version 1.01\n");
  33.   printf ("  by Lobotosoft\n");
  34.   for (i = 0; i < 96; ++i)
  35.     {
  36.     calltime[i] = 0;
  37.     nettime[i] = 0;
  38.     tottime[i] = 0;
  39.     busytime[i] = 0;
  40.  
  41.     }
  42.   for (i = 0; i < 7; ++i)     baud[i] = 0;
  43.   for (i = 0; i < 1440; ++i)  duration[i] = 0;
  44.   writename = DEFAULT_WRITE;
  45.   readname  = DEFAULT_READ;
  46.   if (argc > 2)  readname = argv[2];
  47.   if (argc > 1)  writename = argv[1];
  48.   readfile = fopen (readname, "r");
  49.   if (readfile == NULL)
  50.     {
  51.     fprintf (stderr, "Unable to open log file [%s] for input!\n", readname);
  52.     printf ("Usage: logcrunch [output file] [input file]\n");
  53.     exit (0);
  54.  
  55.     }
  56.   writefile = fopen (writename, "w");
  57.   if (writefile == NULL)
  58.     {
  59.     fprintf (stderr, "Unable to open stats file [%s] for output!\n", writename);
  60.     printf ("Usage: logcrunch [output file] [input file]\n");
  61.     fclose (readfile);
  62.     exit (0);
  63.  
  64.     }
  65.   name      = buffer;
  66.   date      = &buffer[24];
  67.   starthour = &buffer[32];
  68.   startmin  = &buffer[35];
  69.   stophour  = &buffer[40];
  70.   stopmin   = &buffer[43];
  71.   other     = &buffer[47];
  72.   fgets (buffer, 80, readfile);
  73.   while (!feof (readfile))
  74.     {
  75.     if (strncmp (buffer, UP, strlen (UP)) == 0) ++restart;
  76.     if (strlen (buffer) > 23  &&  buffer[22] == ':')
  77.       {
  78.       buffer[22] = 0;
  79.       buffer[31] = 0;
  80.       buffer[37] = 0;
  81.       buffer[42] = 0;
  82.       buffer[45] = 0;
  83.       strcpy (lasttime, starthour);
  84.       strcpy (lastdate, date);
  85.       if (calls == 0  &&  net == 0)
  86.         {
  87.         strcpy (firsttime, starthour);
  88.         strcpy (firstdate, date);
  89.         buffer[34] = 0;
  90.         lasthour = atoi (starthour);
  91.         lastmin = atoi (startmin);
  92.  
  93.         }
  94.       buffer[34] = 0;
  95.       h1 = atoi (starthour);
  96.       h2 = atoi (stophour);
  97.       m1 = atoi (startmin);
  98.       m2 = atoi (stopmin);
  99.       i = h1 * 4 + m1 / 15;
  100.       j = h2 * 4 + m2 / 15;
  101.       k = lasthour * 4 + lastmin / 15;
  102.       tottime[k] += (k + 1) * 15 - lasthour * 60 - lastmin;
  103.       if (j < k)
  104.         {
  105.         for (l = k + 1; l < 96; ++l) tottime[l] += 15;
  106.         for (l = 0; l < j + 1; ++l)  tottime[l] += 15;
  107.         tottime[j] -= (j + 1) * 15 - h2 * 60 - m2;
  108.  
  109.         }
  110.       else
  111.         {
  112.         for (l = k + 1; l < j + 1; ++l) tottime[l] += 15;
  113.         tottime[j] -= (j + 1) * 15 - h2 * 60 - m2;
  114.  
  115.         }
  116.       lasthour = h2;
  117.       lastmin = m2;
  118.       if (strncmp (name, NET, strlen (NET)) == 0)
  119.         {
  120.         ++net;
  121.         ++nettime[i];
  122.         busytime[i] += (i + 1) * 15 - h1 * 60 - m1;
  123.         if (j < i)
  124.           {
  125.           for (l = i + 1; l < 96; ++l) busytime[l] += 15;
  126.           for (l = 0; l < j + 1; ++l)  busytime[l] += 15;
  127.           busytime[j] -= (j + 1) * 15 - h2 * 60 - m2;
  128.  
  129.           }
  130.         else
  131.           {
  132.           for (l = i + 1; l < j + 1; ++l) busytime[l] += 15;
  133.           busytime[j] -= (j + 1) * 15 - h2 * 60 - m2;
  134.  
  135.           }
  136.  
  137.         }
  138.       else
  139.         {
  140.         ++calls;
  141.         ++calltime[i];
  142.         busytime[i] += (i + 1) * 15 - h1 * 60 - m1;
  143.         if (j < i)
  144.           {
  145.           for (l = i + 1; l < 96; ++l) busytime[l] += 15;
  146.           for (l = 0; l < j + 1; ++l)  busytime[l] += 15;
  147.           busytime[j] -= (j + 1) * 15 - h2 * 60 - m2;
  148.  
  149.           }
  150.         else
  151.           {
  152.           for (l = i + 1; l < j + 1; ++l) busytime[l] += 15;
  153.           busytime[j] -= (j + 1) * 15 - h2 * 60 - m2;
  154.  
  155.           }
  156.         l = (h2 - h1) * 60 + m2 - m1;
  157.         if (l < 0)
  158.         l += 1440;
  159.         ++duration[l];
  160.         if (l > longest) longest = l;
  161.         atime += l;
  162.         if (strncmp (NOLOGIN, name,   strlen (NOLOGIN))  == 0) ++nologin;
  163.         if (strncmp (CONSOLE, other,  strlen (CONSOLE))  == 0)++baud[0];
  164.         if (strncmp (BAUD300, other,  strlen (BAUD300))  == 0)++baud[1];
  165.         if (strncmp (BAUD1200, other, strlen (BAUD1200)) == 0)++baud[2];
  166.         if (strncmp (BAUD2400, other, strlen (BAUD2400)) == 0)++baud[3];
  167.         if (strncmp (BAUD4800, other, strlen (BAUD4800)) == 0)++baud[4];
  168.         if (strncmp (BAUD9600, other, strlen (BAUD9600)) == 0)++baud[5];
  169.         if (strncmp (BAUD19200, other,strlen (BAUD19200))== 0)++baud[6];
  170.         for (l = 0; other[l] != ')'  &&  other[l] != 0; ++l);
  171.         for (;other[l] != 0; ++l)
  172.           {
  173.           if (other[l] == '+')
  174.              ++newuser;
  175.           else if (other[l] == '-')
  176.              ++stay;
  177.           else if (other[l] == 't'  ||  other[l] == 'T')
  178.              ++timeout;
  179.           else if (other[l] == 'e'  ||  other[l] == 'E')
  180.              ++error;
  181.           else if (other[l] == 'b'  ||  other[l] == 'B')
  182.              ++badword;
  183.           else if (other[l] == 'c'  ||  other[l] == 'C')
  184.              ++chat;
  185.  
  186.           }
  187.  
  188.         }
  189.  
  190.       }
  191.     fgets (buffer, 80, readfile);
  192.     printf ("%ld calls, %ld net sessions\r", calls, net);
  193.  
  194.     }
  195.   printf ("\nCrunching data....\n");
  196.   fprintf (writefile, "        System Usage Data\n \n");
  197.   fprintf (writefile, "  Based on usage from  %s, %s to %s, %s\n\n"
  198.   , firstdate,firsttime,lastdate,lasttime);
  199.   fprintf (writefile, "        SYSTEM CALL DATA: \n\n");
  200.   fprintf (writefile, " There were %ld restarts during this period.\n", restart);
  201.   fprintf (writefile, " There were %ld calls, and %ld network sessions\n", calls, net);
  202.   fprintf (writefile, "                     Number   Percent\n");
  203.   fprintf (writefile, " -------------------------------------\n");
  204.   fprintf (writefile, " New Users            %5ld     %3ld\n", newuser, 100 * newuser / calls);
  205.   fprintf (writefile, " No Login Calls       %5ld     %3ld\n", nologin, 100 * nologin / calls);
  206.   fprintf (writefile, " .Terminate Stay      %5ld     %3ld\n", stay,    100 * stay / calls);
  207.   fprintf (writefile, " Chat Attempts        %5ld     %3ld\n", chat,    100 * chat / calls);
  208.   fprintf (writefile, " Timeouts             %5ld     %3ld\n", timeout, 100 * timeout / calls);
  209.   fprintf (writefile, " Exceeded Error Limit %5ld     %3ld\n", error,   100 * error / calls);
  210.   fprintf (writefile, " Badwords usage       %5ld     %3ld\n", badword, 100 * badword / calls);
  211.   fprintf (writefile, " \n    Caller Baud Rates:\n");
  212.   if (baud[1] > 0) fprintf (writefile, " 300 Baud             %5ld     %3ld\n", baud[1], 100 * baud[1] / calls);
  213.   if (baud[2] > 0) fprintf (writefile, " 1200 Baud            %5ld     %3ld\n", baud[2], 100 * baud[2] / calls);
  214.   if (baud[3] > 0) fprintf (writefile, " 2400 Baud            %5ld     %3ld\n", baud[3], 100 * baud[3] / calls);
  215.   if (baud[4] > 0) fprintf (writefile, " 4800 Baud            %5ld     %3ld\n", baud[4], 100 * baud[4] / calls);
  216.   if (baud[5] > 0) fprintf (writefile, " 9600 Baud            %5ld     %3ld\n", baud[5], 100 * baud[5] / calls);
  217.   if (baud[6] > 0) fprintf (writefile, " 19200 Baud           %5ld     %3ld\n", baud[6], 100 * baud[6] / calls);
  218.   if (baud[0] > 0) fprintf (writefile, " sysConsole           %5ld     %3ld\n", baud[0], 100 * baud[0] / calls);
  219.   fprintf (writefile, " \n \n   CALL DURATION DATA\n \n");
  220.   fprintf (writefile, "    The longest call was %ld minutes,", longest);
  221.   fprintf (writefile, " The average call was %ld minutes.\n \n", atime /  calls);
  222.   for (k = 0, i = 0; k < calls - calls / 25; ++i)  k += duration[i];
  223.   h1 = calls - k;
  224.   longest = i;
  225.   i = i / 50 + 1;
  226.   for (k = 0, m2 = h1; k < longest; ++k)
  227.     {
  228.     for (l = k * i, m1 = 0; l < (k + 1) * i; ++l) m1 += duration[l];
  229.     duration[k] = m1;
  230.     if (m1 > m2) m2 = m1;
  231.  
  232.     }
  233.   j = m2 / 60 + 1;
  234.   fprintf (writefile, " Call duration histogram:\n");
  235.   fprintf (writefile, "  Each bar represents the number of calls of that\n");
  236.   fprintf (writefile, "  duration or up to %ld minutes longer.", i);
  237.   fprintf (writefile, "  Each '=' represents %ld calls.\n \n", j);
  238.   for (k = 0; longest >= k * i; ++k)
  239.     {
  240.     fprintf (writefile, "  %4ld", k * i);
  241.     for (l = 0; l < duration[k] / j; ++l) fprintf (writefile, "=");
  242.     fprintf (writefile, " (%ld)\n", duration[k]);
  243.  
  244.     }
  245.   fprintf (writefile, " >%4ld", --k * i);
  246.   for (l = 0; l < h1 / j; ++l)
  247.   fprintf (writefile, "=");
  248.   fprintf (writefile, " (%ld)\n", h1);
  249.   fprintf (writefile, " \n \n   CALL TIMING DATA\n \n");
  250.   i = 4;
  251.   m1 = 0;
  252.   m2 = 0;
  253.   for (k = 0; k < 24; ++k)
  254.     {
  255.     h1 = 0;
  256.     h2 = 0;
  257.     for (l = k * i; l < (k + 1) * i; ++l)
  258.       {
  259.       h1 += calltime[l];
  260.       h2 += nettime[l];
  261.  
  262.       }
  263.     calltime[k] = h1;
  264.     nettime[k] = h2;
  265.     if (h1 > m1)    m1 = h1;
  266.     if (h2 > m2)    m2 = h2;
  267.  
  268.     }
  269.   h1 = m1 / 60 + 1;
  270.   h2 = m2 / 60 + 1;
  271.   fprintf (writefile, " Call timing histogram:\n");
  272.   fprintf (writefile, "  Each bar represents the number of calls\n");
  273.   fprintf (writefile, "  during that hour.");
  274.   fprintf (writefile, "  Each '=' represents %ld calls.\n", h1);
  275.   for (k = 0; k < 24; ++k)
  276.     {
  277.     fprintf (writefile, " %2ld:00", k);
  278.     for (l = 0; l < calltime[k] / h1; ++l) fprintf (writefile, "=");
  279.     fprintf (writefile, " (%ld)\n", calltime[k]);
  280.  
  281.     }
  282.   fprintf (writefile, "\n Net-Session timing histogram:\n");
  283.   fprintf (writefile, "  Each bar represents the number of net-sessions\n");
  284.   fprintf (writefile, "  during that hour.");
  285.   fprintf (writefile, "  Each '=' represents %ld net-sessions.\n", h2);
  286.   for (k = 0; k < 24; ++k)
  287.     {
  288.     fprintf (writefile, " %2ld:00", k);
  289.     for (l = 0; l < nettime[k] / h2; ++l) fprintf (writefile, "=");
  290.     fprintf (writefile, " (%ld)\n", nettime[k]);
  291.  
  292.     }
  293.   fprintf (writefile, "\n   BEST TIME TO CALL DATA \n");
  294.   for (i = 0, m1 = 0, j = 0; i < 96; ++i)
  295.     {
  296.     if (tottime[i] == 0)
  297.       {
  298.       fprintf (writefile, "  Best time to call data is unavailable,");
  299.       fprintf (writefile, " since there is less than 24 hours of data.\n");
  300.       fclose (writefile);
  301.       fclose (readfile);
  302.       exit (0);
  303.  
  304.       }
  305.     if ((tottime[i] - busytime[i]) * 100 / tottime[i] > m1)
  306.       {
  307.       m1 = (tottime[i] - busytime[i]) * 100 / tottime[i];
  308.       j = i;
  309.  
  310.       }
  311.  
  312.     }
  313.   fprintf (writefile, " The best time to call is around %ld:%02ld,\n", j / 4, (j % 4) * 15);
  314.   fprintf (writefile, "  when there is a %ld percent chance of connecting.\n",  m1);
  315.   i = 4;
  316.   for (m1 = 0, j = 0; j < 24; ++j)
  317.     {
  318.     for (k = j * i, h1 = 0, h2 = 0; k < (j + 1) * i; ++k)
  319.       {
  320.       h1 += tottime[k];
  321.       h2 += busytime[k];
  322.  
  323.       }
  324.     busytime[j] = (h1 - h2) * 100 / h1;
  325.     if (busytime[j] > m1) m1 = busytime[j];
  326.  
  327.     }
  328.   j = m1 / 60 + 1;
  329.   fprintf (writefile, " \n Best Time to Call Graph:\n");
  330.   fprintf (writefile, "  Each bar represents the chance of connecting\n");
  331.   fprintf (writefile, "   during that hour.\n \n");
  332.   for (k = 0; k < 24; ++k)
  333.     {
  334.     fprintf (writefile, " %2ld:00", k);
  335.     for (l = 0; l < busytime[k] / j; ++l)    fprintf (writefile, "=");
  336.     fprintf (writefile, " %ld\n", busytime[k]);
  337.  
  338.     }
  339.   fclose (readfile);
  340.   fclose (writefile);
  341.  
  342.   }
  343.